package com.ygo.feihua.fragment;
import android.os.*;
import android.support.v4.app.*;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.*;
import com.ygo.feihua.*;
import com.ygo.feihua.adapter.*;
import com.yuyh.library.imgsel.*;
import java.util.*;

import com.ygo.feihua.R;
import android.content.*;
import com.yuyh.library.imgsel.ui.*;
import com.ygo.feihua.util.*;

public class FragmentFtJianyue extends Fragment
{

	private EditText jy_message;
	private GridView jy_grid;
	private ImageSelectAdapter isadp;
	private DialogUtils du;

	public void getMessage()
	{
		FatieMessage fm=new FatieMessage();
		fm.setMessage(jy_message.getText().toString().trim());
		fm.setImage_path("");
		ShequFabu sf=(ShequFabu)getActivity();
		sf.closeMessage();
		sf.addMessage(fm);
		for(int i=0;i<isadp.getCount();i++){
			String s=isadp.getItem(i).toString().trim();
			if(!s.equals("")){
				FatieMessage ffm=new FatieMessage();
				ffm.setMessage("");
				ffm.setImage_path(s);
				sf.addMessage(ffm);
			}
		}
		
		// TODO: Implement this method
	}
	
	public void setMessage(List<FatieMessage> lf){
		String message="";
		isadp.closeImage();
		for(FatieMessage fm:lf){
			if(!fm.getMessage().equals("")){
				message=fm.getMessage()+"\n";
			}
			if(!fm.getImage_path().equals("")){
				isadp.addImage(fm.getImage_path());
			}
		}
		jy_message.setText(message.trim());
		isadp.sx();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		// TODO: Implement this method
		View v=inflater.inflate(R.layout.fragment_ft_jianyue,null);
		initView(v);
		return v;
	}

	private void initView(View v)
	{
		jy_grid=(GridView) v.findViewById(R.id.jy_grid);
		jy_message=(EditText) v.findViewById(R.id.jy_message);
		
		du=DialogUtils.getdx(getActivity());
		List<String> ls=new ArrayList<String>();
		ls.add("");
		isadp=new ImageSelectAdapter(getActivity(),ls);
		jy_grid.setAdapter(isadp);
		
		jy_grid.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> p1, View p2, final int p3, long p4)
				{
					if(p3==0){
					ISNav.getInstance().toListActivity(getActivity(), Gongju.getPicConfig(8), ShequFabu.REQUEST_JIANYUE);
					}else{
						View[] v=du.dialogt(false,"","确定删除图片？");
						Button b1,b2;
						b1=(Button) v[0];
						b2=(Button) v[1];
						b1.setText("取消");
						b2.setText("删除");
						b1.setOnClickListener(new OnClickListener(){

								@Override
								public void onClick(View p1)
								{
									du.dis();
									// TODO: Implement this method
								}
							});
						b2.setOnClickListener(new OnClickListener(){

								@Override
								public void onClick(View p1)
								{
									isadp.removeImage(p3);
									isadp.sx();
									du.dis();
									// TODO: Implement this method
								}
							});
						
					}
					// TODO: Implement this method
				}
			});
		
		// TODO: Implement this method
	}

	
	public void setImage(ArrayList<String> photos){
		for(String s:photos){
			isadp.addImage(s);
		}
		isadp.sx();
	}
	
	
	
	
}
